namespace game {
    export namespace gameConfig {
        export class Resource {

            public static instance: Resource;

            loadList: any[] = [
            ];

            public static async loadResources() {
                if (Resource.instance) {
                    return new Promise<void>(function (resolve: Function) {
                        resolve();
                    });
                }
                Resource.instance = new Resource();
                Resource.instance.loadList = Resource.instance.loadList.concat(ConfigDecode.resources);
                let list: any[] = Resource.instance.loadList;
                return new Promise<void>(function (resolve: Function) {
                    let index = 0;
                    async function load() {
                        if (index >= list.length) {
                            resolve();
                            return;
                        }
                        let res = list[index];
                        if (res.data) {
                            index++;
                            load();
                        } else {
                            cc.resources.load(res.url, function (e: any, data: any) {
                                // console.log('gameConfig', res.url, e, data);
                                res.data = data;
                                index++;
                                if (res.execute) {
                                    res.execute();
                                }
                                load();
                            });
                        }
                    }

                    load();
                }.bind(this));
            }

            public static getResource(name: string): any {
                for (let i = 0; i < Resource.instance.loadList.length; i++) {
                    if (Resource.instance.loadList[i].name == name) {
                        return Resource.instance.loadList[i].data;
                    }
                }
                return null;
            }
        }
    }
}